cmake_minimum_required(VERSION 2.8.4)

SET(PRJ_NAME 				pwshmt)

SET(PRJ_ROOTDIR				${CMAKE_CURRENT_SOURCE_DIR} )
SET(stpool_LIBDIR 				${PRJ_ROOTDIR}/stpool_lib )

## cygwin环境下的程序运行依赖库文件 C:\cygwin64\bin\cygwin1.dll
## 原始路径 C:\cygwin64\bin  
## CMake不能识别字符'\'，需要替换为'/'
SET(CYGWIN_DEPS_DIR			C:/cygwin64/bin )

PROJECT(${PRJ_NAME} 		C CXX)
MESSAGE(STATUS "---PowerShell Multi-threads.")
MESSAGE(STATUS "@@@CMake cmd(Cygwin) -> cmake ..")

INCLUDE_DIRECTORIES( 
	"${PRJ_ROOTDIR}/src"
	"${stpool_LIBDIR}/include/stpool"
)

LINK_DIRECTORIES(
	"${PRJ_ROOTDIR}/build"
	"${stpool_LIBDIR}/lib"
)
	
	SET(cflags	-std=gnu99)
	ADD_DEFINITIONS(${cflags})

	ADD_EXECUTABLE(sample0  ${PRJ_ROOTDIR}/src/sample0.c )

	TARGET_LINK_LIBRARIES(sample0
		-lpthread		#Cygwin Native libraries has 'pthread'
		libstpool.a
		libmsglog.a
	)

	ADD_EXECUTABLE(sample1  ${PRJ_ROOTDIR}/src/sample1.c )
	TARGET_LINK_LIBRARIES(sample1 -lwklds)

	ADD_LIBRARY(wklds SHARED ${PRJ_ROOTDIR}/src/wklds.c)
	TARGET_LINK_LIBRARIES(wklds
		-lpthread
		libstpool.a
		libmsglog.a
	)

add_custom_command(TARGET wklds
			   POST_BUILD 
	COMMAND "${CMAKE_COMMAND}" -E copy ${CYGWIN_DEPS_DIR}/cygwin1.dll 	"$<TARGET_FILE_DIR:wklds>/" 	VERBATIM
)
